
********************************************************************************
cd "R:/Public"
********************************************************************************


*******************************
*Restricted Geo Data
*******************************
use "R:/Restricted/Geographic Information/xyrDet/archive/2012/hrsxgeo12", clear

keep hhid pn gender STATEUSPS98 STATEUSPS00 STATEUSPS02 STATEUSPS04 STATEUSPS06 STATEUSPS08 STATEUSPS10 STATEUSPS12 ZIP98 ZIP00 ZIP02 ZIP04 ZIP06 ZIP08 ZIP10_2000 ZIP10_2010 ZIP12 STFIPS98 STFIPS00 STFIPS02 STFIPS04 STFIPS06 STFIPS08 STFIPS10 STFIPS12 CNTYFIPS98 CNTYFIPS00 CNTYFIPS02 CNTYFIPS04 CNTYFIPS06 CNTYFIPS08 CNTYFIPS10_2000 CNTYFIPS10_2010 CNTYFIPS12 STCNTY98 STCNTY00 STCNTY02 STCNTY04 STCNTY06 STCNTY08 STCNTY10_2000 STCNTY10_2010 STCNTY12 COUNTY98 COUNTY00 COUNTY02 COUNTY04 COUNTY06 COUNTY08 COUNTY10_2000 COUNTY10_2010 COUNTY12
gen id = hhid + pn

save "U:/temp/geodata",  replace



*******
*2002
*******
*******************************
*Module P [Expectations]
*******************************
use "./2002hrs/Final/core/built/stata/H02P_R", clear

gen risk = . // higher numbers more risk averse

replace risk = 6 if HP036 == 1 & HP039 ==1 & HP040 ==1  // most risk averse. not willing to take rist of 1/3, 1/5 or 1/10
replace risk = 5 if HP036 == 1 & HP039 ==1 & HP040 ==2  //  not willing to take rist of 1/3, 1/5 but willing to take 1/10
replace risk = 4 if HP036 == 1 & HP039 ==2   //  not willing to take rist of 1/3 but willing to take 1/5 
replace risk = 3 if HP036 == 2 & HP037 == 1 // willing to take 1/3 but not 1/2 risk
replace risk = 2 if HP036 == 2 & HP037 == 2 & HP038 == 1 // willing to take 1/3, 1/2 but not 3/4 
replace risk = 1 if HP036 == 2 & HP037 == 2 & HP038 == 2 // willing to takeany risk: 1/3, 1/2, 3/4 



gen riskbusiness = .
replace riskbusiness = 6 if HP060 == 1 & HP063 == 1 & HP064 == 1 // most risk averse
replace riskbusiness = 5 if HP060 == 1 & HP063 == 1 & HP064 == 2 // most risk averse
replace riskbusiness = 4 if HP060 == 1 & HP063 == 2
replace riskbusiness = 3 if HP060 == 2 & HP061 == 1 
replace riskbusiness = 2 if HP060 == 2 & HP061 == 2 &  HP062 == 1
replace riskbusiness = 1 if HP060 == 2 & HP061 == 2 &  HP062 == 2


tab riskbusiness
hist riskbusiness

gen riskinherit = . 
replace riskinherit = 6 if HP065 == 5 & HP068 == 5 & HP069 == 5
replace riskinherit = 5 if HP065 == 5 & HP068 == 5 & HP069 == 1
replace riskinherit = 4 if HP065 == 5 & HP068 == 1
replace riskinherit = 3 if HP065 == 1 & HP066 == 5
replace riskinherit = 2 if HP065 == 1 & HP066 == 1 & HP067 == 5 
replace riskinherit = 1 if HP065 == 1 & HP066 == 1 & HP067 == 1 

tab riskinherit
hist riskinherit

keep HHID PN risk riskinherit riskbusiness

drop if riskbusiness ==. & riskinherit == . & risk == . // 10703 obs deleted

sort HHID PN

gen id = HHID + PN


save "U:/temp/p2002", replace

*******************************
*Module B [Demographics]
*******************************

use "./2002hrs/Final/core/built/stata/H02B_R", clear

gen education = .
replace education = 0 if HB014A>=0 & HB014A<=11 & HB014A<. // no high school
replace education = 1 if HB014A ==12 //  high school
replace education = 2 if HB014A>=13 & HB014A<=16 &  HB014A<. // college
replace education = 3 if HB014A == 17 // postgrad

gen yearmoved =HB039 
replace yearmoved = . if yearmoved == 9998 | yearmoved == 9999 
gen monthmoved = HB040
replace monthmoved = . if monthmoved == 98 


keep education yearmoved monthmoved HHID PN
sort HHID PN
gen id = HHID + PN

save "U:/temp/b2002", replace

*******************************
*Module PR
*******************************

use "./2002hrs/Final/core/built/stata/H02PR_R", clear
*gender HX060_R
gen female = 1 if HX060_R == 2
replace female = 0 if HX060_R == 1

* age HX067_R
gen age = 2002 - HX067_R
hist age

keep HHID PN female age
sort HHID PN
gen id = HHID + PN
save "U:/temp/pr2002", replace

*******************************
*Module Q [Income]
*******************************

use "./2002hrs/Final/core/built/stata/H02Q_H", clear
*income HQ020
gen income = HQ020 
sum income, d
replace income = . if income > 749000 
replace income = . if income == 0 
gen logincome = log(income)
replace logincome = . if logincome <5 
hist logincome

bysort HHID: gen alarm = _N!=1
bro HHID income logincome HPN_CS if alarm == 1

gen id = HHID + HPN_CS

keep HHID id income logincome
save "U:/temp/q2002", replace

*******************************
*Module H [Housing]
*******************************

*home owner?
use "./2002hrs/Final/core/built/stata/H02H_H", clear

tab HH004
gen homeown = 1 if HH004 == 1
replace homeown = 0 if HH004 == 2 

gen hometype = ""
replace hometype = "mobile" if HH002 == 1
replace hometype = "house" if HH002 == 2 | HH002 == 3 
replace hometype = "apartment" if HH002 == 4


gen id = HHID + HPN_CS

keep HHID homeown id hometype
save "U:/temp/h2002" ,replace




*******************************
*******************************
*Merge 2002 all info
*******************************
*******************************

use "U:/temp/p2002", clear
merge 1:1 id using "U:/temp/b2002"
drop if _merge ==1 
drop if _merge == 2 
drop _merge
merge 1:1 id using "U:/temp/pr2002"
drop if _merge ==1 
drop if _merge == 2 
drop _merge
merge 1:1 id using "U:/temp/h2002"
drop _merge
merge 1:1 id using "U:/temp/geodata"
drop if _merge == 1 
drop if _merge == 2  
drop _merge


gen year = 2002
save "U:/temp/hrs2002", replace



*******
*2004
*******
*******************************
*Module P [Expectations]
*******************************
use "./2004hrs/Final/core/built/stata/H04P_R", clear

gen risk = . // higher numbers more risk averse

replace risk = 6 if JP036 == 1 & JP039 ==1 & JP040 ==1  // most risk averse. not willing to take rist of 1/3, 1/5 or 1/10
replace risk = 5 if JP036 == 1 & JP039 ==1 & JP040 ==2  //  not willing to take rist of 1/3, 1/5 but willing to take 1/10
replace risk = 4 if JP036 == 1 & JP039 ==2   //  not willing to take rist of 1/3 but willing to take 1/5 
replace risk = 3 if JP036 == 2 & JP037 == 1 // willing to take 1/3 but not 1/2 risk
replace risk = 2 if JP036 == 2 & JP037 == 2 & JP038 == 1 // willing to take 1/3, 1/2 but not 3/4 
replace risk = 1 if JP036 == 2 & JP037 == 2 & JP038 == 2 // willing to takeany risk: 1/3, 1/2, 3/4 

keep HHID PN risk 

sort HHID PN

gen id = HHID + PN

save "U:/temp/p2004", replace

*******************************
*Module A [Interview Details]
*******************************

use "./2004hrs/Final/core/built/stata/H04A_R", clear

tab JA500 JA501


gen posthur = 0 if JA501 == 2004 & JA500 == 2
replace posthur = 0 if JA501 == 2004 & JA500 ==3 
replace posthur = 0 if JA501 == 2004 & JA500 ==4
replace posthur = 0 if JA501 == 2004 & JA500 ==5 
replace posthur = 0 if JA501 == 2004 & JA500 ==6 
replace posthur = 0 if JA501 == 2004 & JA500 ==7 
replace posthur = 1 if JA501 == 2004 & JA500 ==8
replace posthur = 1 if JA501 == 2004 & JA500 ==9 
replace posthur = 1 if JA501 == 2004 & JA500 ==10 
replace posthur = 1 if JA501 == 2004 & JA500 ==11
replace posthur = 1 if JA501 == 2004 & JA500 ==12
replace posthur = 1 if JA501 == 2005 & JA500 ==1
replace posthur = 1 if JA501 == 2005 & JA500 ==2


keep HHID PN posthur
sort HHID PN
gen id = HHID + PN
save "U:/temp/a2004", replace

*******************************
*Module B [Demographics]
*******************************

use "./2004hrs/Final/core/built/stata/H04B_R", clear

tab JB014A

gen education = .
replace education = 0 if JB014A>=0 & JB014A<=11 & JB014A<. // no high school
replace education = 1 if JB014A ==12 //  high school
replace education = 2 if JB014A>=13 & JB014A<=16 &  JB014A<. // college
replace education = 3 if JB014A == 17 // postgrad

tab education



gen yearmoved =JB039 
replace yearmoved = . if yearmoved == 9998 | yearmoved == 9999 
gen monthmoved = JB040
replace monthmoved = . if monthmoved == 98 


keep education yearmoved monthmoved HHID PN
sort HHID PN
gen id = HHID + PN

save "U:/temp/b2004", replace

*******************************
*Module PR
*******************************

use "./2004hrs/Final/core/built/stata/H04PR_R", clear
*gender JX060_R
gen female = 1 if JX060_R == 2
replace female = 0 if JX060_R == 1

* age JX067_R
gen age = 2004 - JX067_R
hist age

keep HHID PN female age
sort HHID PN
gen id = HHID + PN
save "U:/temp/pr2004", replace

*******************************
*Module Q [Income]
*******************************

use "./2004hrs/Final/core/built/stata/H04Q_H", clear
*income JQ020
gen income = JQ020 
sum income, d
replace income = . if income > 630000 
replace income = . if income == 0 
gen logincome = log(income)
replace logincome = . if logincome <5 
hist logincome

bysort HHID: gen alarm = _N!=1
bro HHID income logincome JPN_CS if alarm == 1

gen id = HHID + JPN_CS

keep HHID id income logincome
save "U:/temp/q2004", replace

*******************************
*Module H [Housing]
*******************************

*home owner?
use "./2004hrs/Final/core/built/stata/H04H_H", clear
tab JH004
gen homeown = 1 if JH004 == 1
replace homeown = 0 if JH004 == 2 

gen hometype = ""
replace hometype = "mobile" if JH002 == 1
replace hometype = "house" if JH002 == 2 | JH002 == 3 
replace hometype = "apartment" if JH002 == 4


gen id = HHID + JPN_CS

keep HHID homeown id hometype
save "U:/temp/h2004" ,replace


*******************************
*******************************
*Merge 2004 all info
*******************************
*******************************

use "U:/temp/p2004", clear
merge 1:1 id using "U:/temp/b2004" 
drop if _merge == 1
drop if _merge == 2
drop _merge
merge 1:1 id using "U:/temp/pr2004" 
drop if _merge == 1
drop if _merge == 2
drop _merge
merge 1:1 id using "U:/temp/a2004" 
drop if _merge == 1
drop if _merge == 2
drop _merge
merge 1:1 id using "U:/temp/h2004"
drop _merge
merge 1:1 id using "U:/temp/geodata"
drop if _merge == 1  
drop if _merge == 2  
drop _merge

gen year = 2004
save "U:/temp/hrs2004", replace


*******
*2006
*******
*******************************
*Module P [Expectations]
*******************************
use "./2006hrs/Final/core/stata/H06P_R", clear

gen risk = . // higher numbers more risk averse

replace risk = 6 if KP036 == 1 & KP039 ==1 & KP040 ==1  // most risk averse. not willing to take rist of 1/3, 1/5 or 1/10
replace risk = 5 if KP036 == 1 & KP039 ==1 & KP040 ==2  //  not willing to take rist of 1/3, 1/5 but willing to take 1/10
replace risk = 4 if KP036 == 1 & KP039 ==2   //  not willing to take rist of 1/3 but willing to take 1/5 
replace risk = 3 if KP036 == 2 & KP037 == 1 // willing to take 1/3 but not 1/2 risk
replace risk = 2 if KP036 == 2 & KP037 == 2 & KP038 == 1 // willing to take 1/3, 1/2 but not 3/4 
replace risk = 1 if KP036 == 2 & KP037 == 2 & KP038 == 2 // willing to takeany risk: 1/3, 1/2, 3/4 
tab risk
hist risk


gen riskbusiness = .
replace riskbusiness = 6 if KP060 == 1 & KP063 == 1 & KP064 == 1 // most risk averse
replace riskbusiness = 5 if KP060 == 1 & KP063 == 1 & KP064 == 2 // most risk averse
replace riskbusiness = 4 if KP060 == 1 & KP063 == 2
replace riskbusiness = 3 if KP060 == 2 & KP061 == 1 
replace riskbusiness = 2 if KP060 == 2 & KP061 == 2 &  KP062 == 1
replace riskbusiness = 1 if KP060 == 2 & KP061 == 2 &  KP062 == 2


tab riskbusiness
hist riskbusiness

gen riskinherit = . 
replace riskinherit = 6 if KP065 == 5 & KP068 == 5 & KP069 == 5
replace riskinherit = 5 if KP065 == 5 & KP068 == 5 & KP069 == 1
replace riskinherit = 4 if KP065 == 5 & KP068 == 1
replace riskinherit = 3 if KP065 == 1 & KP066 == 5
replace riskinherit = 2 if KP065 == 1 & KP066 == 1 & KP067 == 5 
replace riskinherit = 1 if KP065 == 1 & KP066 == 1 & KP067 == 1 

tab riskinherit
hist riskinherit


keep HHID PN risk riskbusiness riskinherit

sort HHID PN

gen id = HHID + PN

drop if riskbusiness ==. & riskinherit == . & risk == . 


save "U:/temp/p2006", replace


*******************************
*Module B [Demographics]
*******************************

use "./2006hrs/Final/core/stata/H06B_R", clear

gen yearmoved =KB039 
replace yearmoved = . if yearmoved == 9998 | yearmoved == 9999 
gen monthmoved = KB040
replace monthmoved = . if monthmoved == 98 

tab KB061

keep yearmoved monthmoved HHID PN
sort HHID PN
gen id = HHID + PN

save "U:/temp/b2006", replace

*******************************
*Module PR
*******************************

use "./2006hrs/Final/core/stata/H06PR_R", clear
*gender JX060_R
gen female = 1 if KX060_R == 2
replace female = 0 if KX060_R == 1

* age JX067_R
gen age = 2006 - KX067_R
hist age

keep HHID PN female age
sort HHID PN
gen id = HHID + PN
save "U:/temp/pr2006", replace

*******************************
*Module Q [Income]
*******************************

use "./2006hrs/Final/core/stata/H06Q_H", clear
*income JQ020
gen income = KQ020 
sum income, d
replace income = . if income > 600000 
replace income = . if income == 0 
gen logincome = log(income)
replace logincome = . if logincome <5 
hist logincome

bysort HHID: gen alarm = _N!=1
bro HHID income logincome KPN_CS if alarm == 1

gen id = HHID + KPN_CS

keep HHID id income logincome
save "U:/temp/q2006", replace

*******************************
*Module H [Housing]
*******************************

*home owner?
use "./2006hrs/Final/core/stata/H06H_H", clear
tab KH004
gen homeown = 1 if KH004 == 1
replace homeown = 0 if KH004 == 2 
gen id = HHID + KPN_CS

gen hometype = ""
replace hometype = "mobile" if KH002 == 1
replace hometype = "house" if KH002 == 2 | KH002 == 3 
replace hometype = "apartment" if KH002 == 4

keep HHID homeown id hometype
save "U:/temp/h2006" ,replace


*******************************
*******************************
*Merge 2006 all info
*******************************
*******************************

use "U:/temp/p2006", clear
merge 1:1 id using "U:/temp/b2006"
bro if _merge ==1 
drop if _merge == 2 
drop _merge
merge 1:1 id using "U:/temp/pr2006"
bro if _merge ==1 
bro if _merge == 2 
drop if _merge == 2 
drop _merge
merge 1:1 id using "U:/temp/h2006"
drop _merge
merge 1:1 id using "U:/temp/geodata"
drop if _merge == 1  
drop if _merge == 2  
drop _merge

gen year = 2006
save "U:/temp/hrs2006", replace



********************************************************************************
********************************************************************************
*								Merge all HRS
********************************************************************************
********************************************************************************


use "U:/temp/hrs2002", clear
append using "U:/temp/hrs2004"
append  using "U:/temp/hrs2006"


order HHID PN id year risk riskbusiness riskinherit
sort id year

drop if PN == "" 
drop hhid pn // duplicates

drop gender

rename id idstring
encode idstring, gen(id) 

xtset id year

save "U:/temp/hrs", replace


********************************************************************************
*bringing in hurricane data
********************************************************************************


use "U:/importdata/adddata", clear
reshape wide season name min_hur_dist hur_wind, i(zip) j(idhur)

bysort zip: gen alarm = _N!=1
drop alarm
save "U:/temp/hurdata", replace


use "U:/temp/hrs", clear
drop HHID PN idstring
order id year
sort id year



********************************************************************************
* Investigating Movers

*how many moved?
gen moved0204 = 1 if ZIP02!=ZIP04 & ZIP02!="" & ZIP04 !=""
replace moved0204 = 0 if ZIP02 == ZIP04 & ZIP02!="" & ZIP04 !=""
tab moved0204 

gen moved0206 = 1 if ZIP02!=ZIP06 & ZIP02!="" & ZIP06 !=""
replace moved0206 = 0 if ZIP02==ZIP06 & ZIP02!="" & ZIP06 !=""
tab moved0206 

gen moved0406 = 1 if ZIP04!=ZIP06 & ZIP04!="" & ZIP06 !=""
replace moved0406 = 0 if ZIP04==ZIP06 & ZIP04!="" & ZIP06 !=""
tab moved0406 



gen state = STATEUSPS02 if year == 2002
replace state = STATEUSPS04 if year == 2004
replace state = STATEUSPS06 if year == 2006


gen zip = ZIP02 if year == 2002
replace zip = ZIP04 if year == 2004
replace zip = ZIP06 if year == 2006



keep id year risk* education female age yearmoved monthmoved state zip posthur homeown hometype moved*

merge m:1 zip using "U:/temp/hurdata"
drop if _merge == 1 
drop if _merge == 2 
drop _merge

egen idyear = group(id year)

reshape long season name min_hur_dist hur_wind, i(idyear) j(idhur)

drop idyear
order id year idhur state zip  risk*  

replace min_hur_dist = min_hur_dist /1000  // transforming into km
hist min_hur_dist

drop if min_hur_dist <30 // dropping those hit

gen logd = log(min_hur_dist)


save "U:/temp/hrs_final" ,replace


********************************************************************************
*Analysis
********************************************************************************

use "U:/temp/hrs_final", clear

**By each hurricane
rename hur_wind hurstring
destring hurstring, gen(hur_wind)
drop if hur_wind <64   //619542 obs deleted

drop if idhur == 7 | idhur == 6 | idhur == 5 | idhur == 4 | idhur == 3 | idhur == 2 | idhur == 1 // after survey ended

bysort id idhur: egen atleast2 = count(id)
drop if atleast2== 1 


gen timehur = 2004 if season == 2003 | season == 2004
replace timehur = 2006 if season == 2005 

bysort id timehur: egen double distance = min(min_hur_dist)

gen tokeep =  1 if min_hur_dist == distance
keep if tokeep == 1
drop tokeep

drop if risk == .

gen post = 0 
replace post = 1 if year>=timehur


gen evertr50 = 0
replace evertr50 = 1 if distance<50

gen evertr100 = 0
replace evertr100 = 1 if distance<100


gen evertr150 = 0
replace evertr150 = 1 if distance<150


gen evertr200 = 0
replace evertr200 = 1 if distance<200

gen evertr300 = 0
replace evertr300 = 1 if distance<300

gen evertr400 = 0
replace evertr400 = 1 if distance<400

gen evertr500 = 0
replace evertr500 = 1 if distance<500


gen treatment50 = evertr50 * post
gen treatment100 = evertr100 * post
gen treatment150 = evertr150 * post
gen treatment200 = evertr200 * post
gen treatment300 = evertr300 * post
gen treatment400 = evertr400 * post
gen treatment500 = evertr500 * post

egen group = group (id idhur)

gen didlog = logd*post

xtset group

**Demographics cleaning
bysort id: egen alarm = mean(female)
drop if alarm != 0 & alarm!=1 
drop alarm


gen evertr1000 = 0
replace evertr1000 = 1 if distance<1000
gen treatment1000 = evertr1000 * post

gen evertr2000 = 0
replace evertr2000 = 1 if distance<2000
gen treatment2000 = evertr2000 * post


gen evertr3000 = 0
replace evertr3000 = 1 if distance<3000
gen treatment3000 = evertr3000 * post

gen evertr4000 = 0
replace evertr4000 = 1 if distance<4000
gen treatment4000 = evertr4000 * post

save "U:/temp/hrs_toplot", replace

xtreg risk treatment4000 i.year , fe cl(group)
estimates store risk4000
outreg2 using "U:/export/hrsriskbands.doc",   replace dec(3)
regsave treatment4000 using "U:/temp/riskbands", table(treatment4000, order(regvars)) replace  ci

xtreg risk treatment3000 i.year , fe cl(group)
estimates store risk3000
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment3000 using "U:/temp/riskbands", table(treatment3000, order(regvars)) append  ci

xtreg risk treatment2000 i.year , fe cl(group)
estimates store risk2000
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment2000 using "U:/temp/riskbands", table(treatment2000, order(regvars)) append  ci

xtreg risk treatment1000 i.year , fe cl(group)
estimates store risk1000
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment1000 using "U:/temp/riskbands", table(treatment1000, order(regvars)) append  ci

xtreg risk treatment500 i.year , fe cl(group)
estimates store risk500
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment500 using "U:/temp/riskbands", table(treatment500, order(regvars)) append  ci

xtreg risk treatment400 i.year , fe cl(group)
estimates store risk400
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment400 using "U:/temp/riskbands", table(treatment400, order(regvars)) append  ci

xtreg risk treatment300 i.year , fe cl(group)
estimates store risk300
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment300 using "U:/temp/riskbands", table(treatment300, order(regvars)) append  ci

xtreg risk treatment200 i.year , fe cl(group)
estimates store risk200
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment200 using "U:/temp/riskbands", table(treatment200, order(regvars)) append  ci

xtreg risk treatment150 i.year , fe cl(group)
estimates store risk150
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment150 using "U:/temp/riskbands", table(treatment150, order(regvars)) append  ci

xtreg risk treatment100 i.year , fe cl(group)
estimates store risk100
outreg2 using "U:/export/hrsriskbands.doc",   append dec(3)
regsave treatment100 using "U:/temp/riskbands", table(treatment100, order(regvars)) append  ci

xtreg risk treatment50 i.year , fe cl(group)
estimates store risk50
outreg2 using "U:/export/hrsriskbands.doc",    dec(3) append tex
regsave treatment50 using "U:/temp/riskbands", table(treatment50, order(regvars)) append  ci

xtreg risk didlog logd post i.year, fe cl(group)
outreg2 using "U:/export/didcont.doc", dec(3) append tex

save "U:/temp/toplot", replace


 *** PLOT COEFPLOT FORM MODEL ABOVE
 
use "U:/temp/riskbands", clear

drop if var == "treatment50_stderr"
drop if var == "treatment100_stderr"
drop if var == "treatment150_stderr"
drop if var == "treatment200_stderr"
drop if var == "treatment300_stderr"
drop if var == "treatment400_stderr"
drop if var == "treatment500_stderr"
drop if var == "treatment1000_stderr"
drop if var == "treatment2000_stderr"
drop if var == "treatment3000_stderr"
drop if var == "treatment4000_stderr"
drop if var == "N"
drop if var == "r2"

reshape long treatment, i(var) j(led)
drop if treatment == .

replace var = "coef" if var == "treatment50_coef"
replace var = "coef" if var == "treatment100_coef"
replace var = "coef" if var == "treatment150_coef"
replace var = "coef" if var == "treatment200_coef"
replace var = "coef" if var == "treatment300_coef"
replace var = "coef" if var == "treatment400_coef"
replace var = "coef" if var == "treatment500_coef"
replace var = "coef" if var == "treatment1000_coef"
replace var = "coef" if var == "treatment2000_coef"
replace var = "coef" if var == "treatment3000_coef"
replace var = "coef" if var == "treatment4000_coef"


replace var = "ci_upper" if var == "treatment50_ci_upper"
replace var = "ci_upper" if var == "treatment100_ci_upper"
replace var = "ci_upper" if var == "treatment150_ci_upper"
replace var = "ci_upper" if var == "treatment200_ci_upper"
replace var = "ci_upper" if var == "treatment300_ci_upper"
replace var = "ci_upper" if var == "treatment400_ci_upper"
replace var = "ci_upper" if var == "treatment500_ci_upper"
replace var = "ci_upper" if var == "treatment1000_ci_upper"
replace var = "ci_upper" if var == "treatment2000_ci_upper"
replace var = "ci_upper" if var == "treatment3000_ci_upper"
replace var = "ci_upper" if var == "treatment4000_ci_upper"


replace var = "ci_lower" if var == "treatment50_ci_lower"
replace var = "ci_lower" if var == "treatment100_ci_lower"
replace var = "ci_lower" if var == "treatment150_ci_lower"
replace var = "ci_lower" if var == "treatment200_ci_lower"
replace var = "ci_lower" if var == "treatment300_ci_lower"
replace var = "ci_lower" if var == "treatment400_ci_lower"
replace var = "ci_lower" if var == "treatment500_ci_lower"
replace var = "ci_lower" if var == "treatment1000_ci_lower"
replace var = "ci_lower" if var == "treatment2000_ci_lower"
replace var = "ci_lower" if var == "treatment3000_ci_lower"
replace var = "ci_lower" if var == "treatment4000_ci_lower"


reshape wide treatment, i(var) j (led)


save "U:/temp/coefplot_risk", replace



***************************
*Investigating Movers 
***************************

use "U:/temp/hrs_toplot", clear

reg moved0204 risk if year == 2002 & (state == "AL" | state == "FL" | state == "MS" | state == "NC" | ///
 state == "SC"  | state == "VA" | state == "LA" | state == "TX")
outreg2 using "U:/export/movers.doc", replace dec(3)

reg moved0406 risk if year == 2004 & (state == "AL" | state == "FL" | state == "MS" | state == "NC" | ///
 state == "SC"  | state == "VA" | state == "LA" | state == "TX")
 outreg2 using "U:/export/movers.doc", append dec(3)

reg moved0206 risk if year == 2002 & (state == "AL" | state == "FL" | state == "MS" | state == "NC" | ///
 state == "SC"  | state == "VA" | state == "LA" | state == "TX")
 outreg2 using "U:/export/movers.doc",  dec(3) append tex


********************************************************************************
*** Descriptives 
********************************************************************************

use "U:/temp/hrs_final", clear

**By each hurricane
rename hur_wind hurstring
destring hurstring, gen(hur_wind)

drop if idhur == 7 | idhur == 6 | idhur == 5 | idhur == 4 | idhur == 3 | idhur == 2 | idhur == 1 // after survey ended


bysort id idhur: egen atleast2 = count(id)

drop if atleast2== 1 

gen timehur = 2004 if season == 2003 | season == 2004
replace timehur = 2006 if season == 2005 

bysort id timehur: egen double distance = min(min_hur_dist)

gen tokeep =  1 if min_hur_dist == distance
keep if tokeep == 1
drop tokeep


**Demographics cleaning
bysort id: egen alarm = mean(female)
drop if alarm != 0 & alarm!=1 // 76 obs
drop alarm

gen ishur =1 if hur_wind >=64 & hur_wind !=.
replace ishur = 0 if hur_wind < 64 & hur_wind !=.

reg risk c.logd##ishur female i.year
margins, dydx(logd) at(ishur = (0 1))
marginsplot

use "U:/temp/hrs_final", clear

**By each hurricane
rename hur_wind hurstring
destring hurstring, gen(hur_wind)
drop if idhur == 7 | idhur == 6 | idhur == 5 | idhur == 4 | idhur == 3 | idhur == 2 | idhur == 1 // after survey ended


bysort id idhur: egen atleast2 = count(id)

drop if atleast2== 1 

gen timehur = 2004 if season == 2003 | season == 2004
replace timehur = 2006 if season == 2005 

bysort id timehur: egen double distance = min(min_hur_dist)

gen tokeep =  1 if min_hur_dist == distance
keep if tokeep == 1
drop tokeep


**Demographics cleaning
bysort id: egen alarm = mean(female)
drop if alarm != 0 & alarm!=1 // 61 obs
drop alarm

keep if state =="FL" | state == "LA" | state=="TX"| state=="AL" | state=="NC" | state== "SC" | state == "VA"| state=="MS"

gen stateid = 1 if state=="AL"
replace stateid =2 if state == "FL"
replace stateid =3 if state == "LA"
replace stateid =4 if state == "NC"
replace stateid =5 if state == "MS"
replace stateid =6 if state == "SC"
replace stateid =7 if state == "TX"
replace stateid =8 if state == "VA"

save "U:/temp/toplot_descriptive1", replace



